<template>
  <view class="query_container">
    <!-- 商品展示区域 -->
    <scroll-view
      :scroll-y="true"
      class="scroll-y"
      @scrolltolower="scroll_bottom"
    >
      <view class="empty" style="text-align: center" v-if="goodList.length == 0"
        >暂无推广中商品</view
      >
      <good-info
        :goodsList="goodList"
        @reload="reload"
        type="promotion"
        :timestamp="timestamp"
      ></good-info>
    </scroll-view>
    <view class="toAssistant1" @tap="go_change_outgoods">新增推广商品</view>
    <!-- <van-empty description="描述文字" /> -->

    <!-- 商品展示区域 -->

    <van-toast id="van-toast" />
    <van-dialog id="van-dialog" zIndex="99999999999" />
  </view>
</template>

<script>
import GoodInfo from "../components/good_info";
import Dialog from "../../wxcomponents/vant/dialog/dialog";
import { show_tj_goods } from "../../utils/imapi";
export default {
  props: {},
  components: {
    GoodInfo,
  },
  data() {
    return {
      value: "",
      option1: [
        { text: "全部", value: "" },
        { text: "仓库中", value: 0 },
        { text: "已上架", value: 1 },
        { text: "提审中", value: 2 },
        { text: "审核成功", value: 3 },
        { text: "审核失败", value: 4 },
      ],
      value1: 0,
      goodList: [],
      mode_show: false,
      good_info: {},
      timestamp: "",
    };
  },
  computed: {},
  watch: {},
  onLoad(options) {
    console.log(options);
    if (options.type == "near") {
      this.mch_type = "near";
    }
    console.log(this.mch_type);
  },
  onReady() {},
  onShow() {
    this.query_all_goods();
  },
  methods: {
    go_change_outgoods() {
      uni.navigateTo({
        url:
          "/pages/query_bargin_goods/query_bargin_goods?type=promotion&goods_status=1",
      });
    },
    async query_all_goods() {
      const timestamp = Date.parse(new Date()).toString();
      try {
        const data = await show_tj_goods();
        console.log(data);
        this.goodList = [];
        if (data.code == 0) {
          if (data.data == null) {
            this.goodList = [];
          } else {
            this.timestamp = timestamp;
            data.data.forEach((item) => {
              this.goodList.push({ goods: item });
            });
          }

          console.log(this.goodList);
        }
        return data;
      } catch (error) {}
    },

    async scroll_bottom() {
      console.log("触底了");
      this.queryparam.page_index++;
      try {
        const data = await query_all_goods(this.queryparam);
        const toast = this.$toast.loading("加载中");
        if (data.code == 0) {
          this.goodList.push(...data.data);
          console.log(data);
          toast.clear();
          if (data.data.length == 0) {
            this.queryparam.page_index--;

            this.$toast("全部加载");
          }
        }
      } catch (error) {}
    },
    close_mode() {},
  },
  onReachBottom() {},
  onHide() {},
  async onPullDownRefresh() {
    const res = await this.query_all_goods();
    if (res) {
      if (res.code == 0) {
        uni.showToast({
          title: "加载成功",
          duration: 2000,
          icon: "none",
        });
      }
      uni.stopPullDownRefresh();
    }
  },
};
</script>

<style scoped lang="scss">
.query_container {
  // position: relative;
  // display: flex;
  // flex-direction: column;
  // overflow: hidden;
  // height: 100vh;
  .scroll-y {
    // flex: 1;
    // position: relative;
    // overflow-y: scroll;
    // padding-bottom: 100rpx;
  }
}
.toAssistant1 {
  position: fixed;
  bottom: 10upx;
  width: 690upx;
  left: 30upx;
  /* right: 0; */
  height: 80upx;
  background: #f03752;
  border-radius: 50upx;
  text-align: center;
  line-height: 80upx;
  font-size: 32upx;
  color: #fff;
  font-weight: 600;
  font-family: PingFangSC-Semibold, PingFang SC;
  z-index: 99;
  /* margin-top: 60upx; */
}
</style>
